import 'package:flutter/material.dart';
import 'package:shop/pages/lease_tools_screen.dart';
import 'package:shop/pages/mine_screen.dart';
import 'package:shop/pages/train_screen.dart';
import 'package:shop/pages/home_screen.dart';
import 'package:shop/pages/select_buy_screen.dart';

class NavigationKeepAlive extends StatefulWidget{

  @override
  _NavigationKeepAliveState createState() => _NavigationKeepAliveState();
}

class _NavigationKeepAliveState extends State<NavigationKeepAlive> with SingleTickerProviderStateMixin{
  final _bottomNavigationColor = Colors.blue;
  int _currentIndex = 0;
  var _controller = PageController(
    initialPage: 0,
  );

  @override
  void dispose(){
    super.dispose();
    _controller.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: _controller,
        children: <Widget>[
          HomeScreen(),
          SelectBuyScreen(),
          TrainScreen(),
          LeaseToolsScreen(),
          MineScreen()
        ],
        physics: NeverScrollableScrollPhysics(),
      ),
      bottomNavigationBar: BottomNavigationBar(
          currentIndex: _currentIndex,
          onTap: (index){
            _controller.jumpToPage(index);
            setState(() {
              _currentIndex = index;
            });
          },
          type: BottomNavigationBarType.fixed,
          items: [
            BottomNavigationBarItem(
                icon: new Image.asset('res/images/icon_home_normal.png', width: 25, height: 25),
                activeIcon: new Image.asset('res/images/icon_home_selected.png', width: 25, height: 25),
                title: Text(
                  '首页',
                  style: TextStyle(color: _bottomNavigationColor),
                )),
            BottomNavigationBarItem(
                icon: new Image.asset('res/images/icon_buy_normal.png', width: 25, height: 25),
                activeIcon: new Image.asset('res/images/icon_buy_selected.png', width: 25, height: 25),
                title: Text(
                  '我也选购',
                  style: TextStyle(color: _bottomNavigationColor),
                )),
            BottomNavigationBarItem(
                icon: new Image.asset('res/images/icon_train_normal.png', width: 25, height: 25),
                activeIcon: new Image.asset('res/images/icon_train_selected.png', width: 25, height: 25),
                title: Text(
                  '培训/认证',
                  style: TextStyle(color: _bottomNavigationColor),
                )),
            BottomNavigationBarItem(
                icon: new Image.asset('res/images/icon_lease_tools_normal.png', width: 25, height: 25),
                activeIcon: new Image.asset('res/images/icon_lease_tools_selected.png', width: 25, height: 25),
                title: Text(
                  '租赁工具',
                  style: TextStyle(color: _bottomNavigationColor),
                )),
            BottomNavigationBarItem(
                icon: new Image.asset('res/images/icon_mine_normal.png', width: 25, height: 25),
                activeIcon: new Image.asset('res/images/icon_mine_selected.png', width: 25, height: 25),
                title: Text(
                  '我的',
                  style: TextStyle(color: _bottomNavigationColor),
                )),
          ]
      ),
    );
  }

}